﻿using System.Collections.Generic;

namespace System.Windows.Media
{
    public static class PathGeometryExtension
    {
        public static void AddLines(this PathGeometry path, IList<Point> points)
        {
            if (points.Count > 1)
            {
                var geometry = new StreamGeometry();
                using (StreamGeometryContext ctx = geometry.Open())
                {
                    ctx.BeginFigure(points[0], false /* is filled */, false /* is closed */);

                    for (int i = 1; i < points.Count; i++)
                    {
                        ctx.LineTo(points[i], true /* is stroked */, false /* is smooth join */);
                    }
                }
                geometry.Freeze();

                path.AddGeometry(geometry);
            }
        }

        public static void AddPolygon(this PathGeometry path, IList<Point> points)
        {
            if (points.Count > 1)
            {
                var geometry = new StreamGeometry();
                using (StreamGeometryContext ctx = geometry.Open())
                {
                    ctx.BeginFigure(points[0], true /* is filled */, true /* is closed */);

                    for (int i = 1; i < points.Count; i++)
                    {
                        ctx.LineTo(points[i], true /* is stroked */, false /* is smooth join */);
                    }
                }
                geometry.Freeze();

                path.AddGeometry(geometry);
            }
        }
    }
}